<?php

namespace app\controller\api;

use app\BaseController;
use app\logic\UserLogic;

class User extends BaseController
{
    public function login()
    {
        $data = $this->getData(['mobile', 'pwd'], ['mobile|手机号' => 'require|mobile', 'pwd|密码' => 'require|alphaDash']);
        if ($token = UserLogic::login($data))
            \Api::success(['token' => $token]);
        \Api::error('账号或密码错误！');
    }

    public function new_token()
    {
        $user = $this->request->__get('user');
        if ($token = UserLogic::newToken($user))
            \Api::success(['token' => $token]);
        \Api::error();
    }
}